import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'

// 开发环境地址
const proxyAddress = 'http://192.168.0.21:5850'
// 测试环境地址
// const proxyAddress = 'http://192.168.0.200:5850'
// const proxyAddress = 'http://192.168.0.243:5850'

const argv = process.argv
const publicPathKey = argv.filter(item => item.includes('publicPath='))[0]
const publicPathVal = publicPathKey ? '/' + publicPathKey.split('=')[1] : '/kf'

function pathResolve(dir) {
  return resolve(process.cwd(), '.', dir)
}

export default {
  base: publicPathVal + '/',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  server: {
    host: '0.0.0.0',
    port: 8082,
    open: true,
    proxy: {
      '/auth': { target: proxyAddress },
      '/form': { target: proxyAddress },
      '/oauth': { target: proxyAddress },
      '/user': { target: proxyAddress },
      '/management': { target: proxyAddress },
      '/api': { target: proxyAddress },
      '/dir': { target: proxyAddress },
      '/open': { target: proxyAddress },
      '/batch': { target: proxyAddress },
      '/cms': { target: proxyAddress },
      '/analysis': { target: proxyAddress },
      '/dxp-web': { target: proxyAddress },
      '/datacenter': { target: proxyAddress },
      '/metadata': { target: proxyAddress },
      '/kfWechatUser': { target: proxyAddress },
      '/preQuestion': { target: proxyAddress },
    },
  },
  resolve: {
    alias: {
      '@': pathResolve('./src'),
    },
  },
}
